import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from 'share/errorMessage'

export default {

  //获取服务列表
  getServiceList(params) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/charge/strategy/all/list`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取服务详情
  getServiceDetail(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/charge/strategy/detail`, {id}).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //新建、更新订单
  createOrder(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/order/info`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  getOrderDetail(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/order/info/detail`, {id}).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取默认地址
  getDefaultAddress() {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/billing/contacts/default`).then(res => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      })
    })
  },

  //申请开票
  newInvoice(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/operation/invoice/info`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //修改订单子状态
  updateOrderSubStatus(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/order/info/offLine/paid`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //修改订单子状态
  payForNow(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/alipay/api/payment/order/prepay`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //启用禁用发票查验
  enableCheck(text, params) {
    return new Promise((resolve, reject) => {
      let method = text ? "post" : "delete";
      httpFetch[method](`${config.baseUrl}/api/legalEntity/with/order`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取列表数据
  getTableData(params) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/legalEntity/with/order/page`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //搜素列表
  handleSearch(keyword) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  getServiceBank() {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/operationservice/public/enum/item/codes?codes=BANK`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

}
